Home:ALL Converter>Prolog predicate sorting a list with respect to sublist

Prolog predicate sorting a list with respect to sublist

Ask Time:2015-03-31T03:05:54         Author:myagmur

Json Formatter

In prolog I tried to write a predicate which takes three parameters first one is a sublist of second one , third one is the sorted one which includes first parameter and then second with respect to first one.

find([a ,c,d] , [a,b,c,d,e,f], Result). 

Result should be [a,c,d,b,e,f].

My code is not working well

find(First,Second,X):-
findall(K, (member(K,Second),
           \+member(K,First),
           append(First,K)), X).

Author:myagmur,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/29354203/prolog-predicate-sorting-a-list-with-respect-to-sublist
yy